package indi.zhifa.recipe.bailan.framework.auth.controller.api;

import indi.zhifa.recipe.bailan.framework.auth.entity.vo.PasswdEncryptKeyVo;
import indi.zhifa.recipe.bailan.framework.auth.util.IZfEncryptUtil;
import indi.zhifa.recipe.bailan.framework.common.entity.annotations.UnLogin;
import indi.zhifa.recipe.bailan.framework.common.entity.annotations.ZfRestController;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Validated
@Api(tags = "TestCryptoApi-测试密码接口")
@RequestMapping("/api/test/crypto")
@Slf4j
@ZfRestController
@RequiredArgsConstructor
public class CryptoTestApi {

    final IZfEncryptUtil mZfEncryptUtil;

    @UnLogin
    @Operation(summary = "aes获取密钥")
    @GetMapping(value = "/aes/key")
    public String getAesSec(){
        return mZfEncryptUtil.aesKey();
    }

    @UnLogin
    @Operation(summary = "aes编码")
    @GetMapping(value = "/aes/encode")
    public String aesEncode(@Parameter(description = "明文") @RequestParam(name = "content") String pContent){
        return mZfEncryptUtil.aesEncode(pContent);
    }

    @UnLogin
    @Operation(summary = "aes解码")
    @GetMapping(value = "/aes/decode")
    public String aesDecode(@Parameter(description = "密文") @RequestParam(name = "content") String pCipherText){
        return mZfEncryptUtil.aesDecode(pCipherText);
    }

    @UnLogin
    @Operation(summary = "des获取密钥")
    @GetMapping(value = "/des/key")
    public String getDesSec(){
        return mZfEncryptUtil.desKey();
    }

    @UnLogin
    @Operation(summary = "des编码")
    @GetMapping(value = "/des/encode")
    public String desEncode(@Parameter(description = "明文") @RequestParam(name = "content") String pContent){
        return mZfEncryptUtil.desEncode(pContent);
    }

    @UnLogin
    @Operation(summary = "des解码")
    @GetMapping(value = "/des/decode")
    public String desDecode(@Parameter(description = "密文") @RequestParam(name = "content") String pCipherText){
        return mZfEncryptUtil.desDecode(pCipherText);
    }

    @UnLogin
    @Operation(summary = "rsa获取密钥")
    @GetMapping(value = "/rsa/key")
    String rsaKey(){
        return mZfEncryptUtil.rsaKey();
    }

    @UnLogin
    @Operation(summary = "rsa编码")
    @GetMapping(value = "/rsa/encode")
    String rsaEncode(String pContent){
        return mZfEncryptUtil.rsaEncode(pContent);
    }

    @UnLogin
    @Operation(summary = "rsa解码")
    @GetMapping(value = "/rsa/decode")
    String rsaDecode(String pCode){
        return mZfEncryptUtil.rsaDecode(pCode);
    }

    @UnLogin
    @Operation(summary = "sm2获取密钥")
    @GetMapping(value = "/sm2/key")
    String sm2Key(){
        return mZfEncryptUtil.sm2Key();
    }

    @UnLogin
    @Operation(summary = "sm2编码")
    @GetMapping(value = "/sm2/encode")
    String sm2Encode(String pContent){
        return mZfEncryptUtil.sm2Encode(pContent);
    }

    @UnLogin
    @Operation(summary = "sm2解码")
    @GetMapping(value = "/sm2/decode")
    String sm2Decode(String pCode){
        return mZfEncryptUtil.sm2Decode(pCode);
    }

    @UnLogin
    @Operation(summary = "用户加密密钥")
    @GetMapping(value = "/userName/key")
    String userNameKey(){
        return mZfEncryptUtil.userNameKey();
    }

    @UnLogin
    @Operation(summary = "用户名加密")
    @GetMapping(value = "/userName/encode")
    String userNameEncode(@Parameter(description = "用户名明文") @RequestParam(name = "userName") String pUserName){
        return mZfEncryptUtil.userNameEncode(pUserName);
    }

    @UnLogin
    @Operation(summary = "用户名解密")
    @GetMapping(value = "/userName/decode")
    String userNameDecode(@Parameter(description = "用户名密文") @RequestParam(name = "cipherText") String pCiphertext){
        return mZfEncryptUtil.userNameDecode(pCiphertext);
    }

    @UnLogin
    @Operation(summary = "密码加密密钥")
    @GetMapping(value = "/passwd/key")
    PasswdEncryptKeyVo passwdKey(){
        return mZfEncryptUtil.passwdKey();
    }
    @UnLogin
    @Operation(summary = "密码加密")
    @GetMapping(value = "/passwd/encode")
    String passwdEncode(@Parameter(description = "密码明文") @RequestParam(name = "passwd") String pPasswd){
        return mZfEncryptUtil.passwdEncode(pPasswd);
    }
    @UnLogin
    @Operation(summary = "密码解密")
    @GetMapping(value = "/passwd/swcode")
    String passwdDecode(@Parameter(description = "密码密文") @RequestParam(name = "cipherText") String pCiphertext){
        return mZfEncryptUtil.passwdDecode(pCiphertext);
    }

}
